import time

from selenium.webdriver.common.by import By
from page_object.page_object_02.Page import Page


class Page2(Page):
    # 定位器
    # 页面元素的封装
    # 1输入框: 国台
    search_loc = (By.TAG_NAME, 'input')

    def search(self):
        self.send_keys(self.search_loc, '国台')

    # 2对输入框做回车事件
    def search_enter(self):
        self.keys_enter(self.search_loc)

    # 3点击店铺
    dpbtn_loc = (By.XPATH, '//a[@href=" http://shop.jiuxian.com/brand-20.htm "]')

    def dianpubuttun(self):
        self.click(self.dpbtn_loc)

    # 6点击加入购物车
    card_loc = (By.XPATH, '//area[@href="http://www.jiuxian.com/goods-28877.html"]')

    # 滚动到指定元素位置
    def scroll_element(self):
        self.scroll_to_element(self.card_loc)

    def card(self):
        self.click(self.card_loc)

    # 8点击到货通知
    tocard_loc = (By.ID, 'detail_jiarugouwuche')

    def tocard(self):
        self.click(self.tocard_loc)

    # 9输入通知邮箱号：norma_bai@126.com(清除输入框)
    notify_loc = (By.CLASS_NAME, 'notify-form')

    def notify_clear(self):
        self.clear(self.notify_loc)

    def notify_send(self):
        self.send_keys(self.notify_loc, '2318636512@qq.com')

    # 10点击确定
    notify_sure_loc = (By.CLASS_NAME, 'notify-sure')

    def notify_sure(self):
        self.click(self.notify_sure_loc)

    # 断言：我们会在到货后第一时间给您通知，谢谢关注！
    bind_send_text_loc = (By.CLASS_NAME, 'bind-send-text')

    def bind_send_text(self):
        print(self.text(self.bind_send_text_loc))

    # 11点击确定
    sure_loc = (By.ID, 'notify-popSuc-sure')

    def sure(self):
        self.click(self.sure_loc)

    # 业务逻辑
    def jiuxian2_luoji(self):
        self.jiuxian_login()   # 前置条件--已登录
        # 1输入框: 国台
        self.search()
        # 2对输入框做回车事件
        self.search_enter()
        # 3点击店铺
        self.dianpubuttun()
        # 4窗口切换
        self.new_window()
        # 5 向下滚动600像素
        self.scroll_to_px(600)
        # self.scroll_element()
        time.sleep(3)
        # 6点击加入购物车
        self.card()
        # フ窗口切换
        self.new_window()
        # 8点击到货通知
        self.tocard()
        # 9输入通知邮箱号：norma_bai@126.com(清除输入框)
        self.notify_clear()
        self.notify_send()
        # 10点击确定
        self.notify_sure()
        # 断言：我们会在到货后第一时间给您通知，谢谢关注！
        self.bind_send_text()
        # 11点击确定
        self.sure()









